package com.lh.principle.ocp.improve;

public class Ocp {
	public static void main(String[] args) {
		//使用看看存在的问题
		GraphicEditor graphicEditor = new GraphicEditor();
		graphicEditor.drawShape(new Rectangle());

		graphicEditor.drawShape(new Circle());

		//绘制三角形
		graphicEditor.drawShape(new Triangle());

		//其他图形
		graphicEditor.drawShape(new OtherGraph());

	}
}

//这是一个绘图的类 [使用方]
class GraphicEditor {
	// 接受Shape对象，调用draw方法
	public void drawShape(Shape s) {
		s.draw();
	}
}

//Shape类，基类
abstract class Shape {
	//int m_type;

	//抽象方法
	public abstract void draw();

}

class Rectangle extends Shape {
	//Rectangle() {
	//super.m_type = 1;
	//}

	@Override
	public void draw() {
		// TODO Auto-generated method stub
		System.out.println("绘制矩形");

	}
}

class Circle extends Shape {
	//Circle() {
	//	super.m_type = 2;
	//}

	@Override
	public void draw() {
		// TODO Auto-generated method stub
		System.out.println("绘制圆形");
	}
}


//新增画三角形
class Triangle extends Shape{
	//Triangle() {
	//	super.m_type = 3;
	//}
	@Override
	public void draw() {
		// TODO Auto-generated method stub
		System.out.println("绘制三角形");
	}

}

//新增一个图形
class OtherGraph extends Shape{

	//OtherGraph() {
	// TODO Auto-generated constructor stub
	//	super.m_type = 4;
	//}


	@Override
	public void draw() {
		// TODO Auto-generated method stub
		System.out.println("绘制其他图形");
	}

}


